'use strict';
const gulp = require("gulp");
const minify = require('gulp-minify');
const ts = require('gulp-typescript');
const tsProject = ts.createProject('tsconfig.json');
const inject = require('gulp-inject-string');


gulp.task('buildJs', () => {
    return tsProject.src()
        .pipe(tsProject())
        .js.pipe(inject.replace('var et;', ''))
        .pipe(inject.prepend('window.et = {};\nwindow.egametang = window.et;\n'))
        .pipe(inject.replace('var __extends', 'window.__extends'))
        .pipe(minify({ ext: { min: ".min.js" } }))
        .pipe(gulp.dest('./'));
})

gulp.task("buildDts", () => {
    return tsProject.src()
        .pipe(tsProject())
        .dts.pipe(inject.append('import egametang = et;'))
        .pipe(gulp.dest('./'));
});

gulp.task('build', gulp.series(
    gulp.parallel('buildDts'),
    gulp.parallel('buildJs'),
)
)